#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int ans[10][10], stk[N];

struct DLX {
  static const int M = 1e5 + 10;
  using arr = int[M];
  int n, m, tot;
  arr first, siz;
  arr L, R, U, D;
  arr col, row;

  void build(const int r, const int c) {
    n = r, m = c;
    for (int i = 0; i <= c; ++i) {
      L[i] = i - 1, R[i] = i + 1;
      U[i] = D[i] = i;
    }
    L[0] = c, R[c] = 0, tot = c;
    memset(first, 0, sizeof(first));
    memset(siz, 0, sizeof(siz));
  }

  void insert(const int r, const int c) {
    col[++tot] = c, row[tot] = r, ++siz[c];
    D[tot] = D[c], U[D[c]] = tot, U[tot] = c, D[c] = tot;
    if (!first[r])
      first[r] = L[tot] = R[tot] = tot;
    else {
      R[tot] = R[first[r]], L[R[first[r]]] = tot;
      L[tot] = first[r], R[first[r]] = tot;
    }
  }

  void remove(const int c) {
    L[R[c]] = L[c], R[L[c]] = R[c];
    for (int i = D[c]; i != c; i = D[i])
      for (int j = R[i]; j != i; j = R[j])
        U[D[j]] = U[j], D[U[j]] = D[j], --siz[col[j]];
  }

  void recover(const int c) {
    for (int i = U[c]; i != c; i = U[i])
      for (int j = L[i]; j != i; j = L[j]) {
        U[D[j]] = D[U[j]] = j, ++siz[col[j]];
      }
    L[R[c]] = R[L[c]] = c;
  }

  bool dance(int dep) {
    int c = R[0];
    if (!c) {
      for (int i = 1; i < dep; ++i) {
        int x = (stk[i] - 1) / 9 / 9 + 1;
        int y = (stk[i] - 1) / 9 % 9 + 1;
        int v = (stk[i] - 1) % 9 + 1;
        ans[x][y] = v;
      }
      return true;
    }
    for (int i = c; i != 0; i = R[i])
      if (siz[i] < siz[c]) c = i;
    remove(c);
    for (int i = D[c]; i != c; i = D[i]) {
      stk[dep] = row[i];
      for (int j = R[i]; j != i; j = R[j]) remove(col[j]);
      if (dance(dep + 1)) return true;
      for (int j = L[i]; j != i; j = L[j]) recover(col[j]);
    }
    recover(c);
    return false;
  }
} solver;

int GetId(int row, int col, int num) {
  return (row - 1) * 9 * 9 + (col - 1) * 9 + num;
}

int GetRoom(int row, int col) {
  int dx = (row - 1) / 3 + 1;
  int dy = (col - 1) / 3 + 1;
  return (dx - 1) * 3 + dy;
}

/**
 * ans[row][col] = num 是一种可能情况
 */
void Insert(int row, int col, int num) {
  int room = GetRoom(row, col);
  int id = GetId(row, col, num);
  int f1 = (row - 1) * 9 + num,            // 第 row 行用了一个 num
      f2 = 81 + (col - 1) * 9 + num,       // 第 col 列用了一个 num
      f3 = 81 * 2 + (room - 1) * 9 + num,  // 第 room 宫用了一个 num
      f4 = 81 * 3 + (row - 1) * 9 + col;   // (row, col) 中填了一个数
  for (auto f : {f1, f2, f3, f4}) solver.insert(id, f);
}

int main() {
  solver.build(729, 324);
  for (int i = 1; i <= 9; ++i)
    for (int j = 1; j <= 9; ++j) {
      cin >> ans[i][j];
      for (int v = 1; v <= 9; ++v) {
        if (!ans[i][j] || ans[i][j] == v) Insert(i, j, v);
      }
    }
  solver.dance(1);
  for (int i = 1; i <= 9; ++i, putchar('\n'))
    for (int j = 1; j <= 9; ++j) printf("%d ", ans[i][j]);
}
